<?php

namespace App\Models;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Model;


/**
 * Model FilesModel
 *
 * @property int $id
 * @property string $name
 * @property string $type
 * @property int $size
 * @property string $path
 * @property string $fileable_type
 * @property int $fileable_id
 * @property string $created_at
 * @property string $updated_at
 *
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel where($column, $operator = null, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel whereIn($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel leftJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel rightJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel get($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel find($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel first($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel select($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\FilesModel orderBy($column, $direction = 'asc')
 * @package App\Model
 */

class FilesModel extends BaseModel
{
    protected $table = 'files';

    public function filter($data)
    {
        //
        $where = [];
        if (isset($data['id']))
        {
            $where[] = ['id', '=', $data['id']];
        }
        if (isset($data['is_valid']))
        {
            $where[] = ['is_valid', '=', $data['is_valid']];
        }
        $this->getQueryByModel()->where($where);

        if ($this->getQueryByModel()->hasNamedScope("filter") && class_exists($this->getModelFilterClass())) {
            $this->getQueryByModel()->filter($data);
        }

        return $this->getQueryByModel();
    }
}
